package com.tij;

import java.util.ArrayList;

/**
 * @ClassName:沙鼠案例1
 * @author:
 * @Description: TODO
 * data:2024/10/3 15:12
 * @since
 **/
public class GerbilList {


    public static void main(String[] args) {
        ArrayList<Gerbil> gerbils = new ArrayList<>();
        for(int i =0 ;i <10;i++){
            gerbils.add(new Gerbil());
        }
        for (Gerbil g:gerbils
             ) {
            g.hop();
        }
    }

}

class Gerbil{
    public static int counter;
    public final int gerbilNumber ;

    public Gerbil() {
        this.gerbilNumber = ++counter;
    }

    public void hop(){
        System.out.println("沙鼠"+this.gerbilNumber + "号 正在跳跃...");
    }
}
